package com.group8.ge;


import java.util.Enumeration;
import java.util.Random;
import java.util.Vector;

public class Map {
	private Vector<Plate> plates;
	private Vector<Enemy> enemies;
	private Vector<Bonus> bonuses;
	private Noodle noodle;
	private int inPageP;
	private MapManager mm;
	public Map(MapManager mm, int count){
		this.mm = mm;
		inPageP = count;
		plates = new Vector<Plate>();
		enemies = new Vector<Enemy>();
		bonuses = new Vector<Bonus>();

	}
	public void addPlate(Plate plate) {
		plates.addElement(plate);
	}
	
	public void generateBonus(Plate plate) {
		Bonus b;
		Random generator = new Random();
		int bType = generator.nextInt(3);
		if(bType == 0){
			b = new GunBonus(plate);
		}
		else if(bType == 1){
			int pAmount = generator.nextInt(150);
			b = new PointBonus(plate, pAmount);
		}
		else{
			int hAmount = generator.nextInt(50);
			b = new HoppingBonus(plate, hAmount);
		}
		b.setX(plate.getX()+25);
		b.setY(plate.getY()-50);
		b.setHeight(50);
		b.setWidth(50);
		//System.out.println("bonusssssssssssssssssssssssssssssssssssssssssss added");
		bonuses.addElement(b);
	}
	

	
	public void goDown(){
		for(Plate p: plates) {
			p.setY(p.getY()+1);
		}
		for(Enemy p: enemies) {
			p.setY(p.getY()+1);
		}
		for(Bonus p: bonuses) {
			p.setY(p.getY()+1);
		}
	}
	
	public void generatePlates() {
		if(plates.size() < inPageP){
			Random generator = new Random();
			double x = generator.nextDouble()*700;
			double y = generator.nextDouble()*640;
			Plate p;
			
			int b = generator.nextInt(5);
			int m = generator.nextInt(6);
			if(b % 5 == 0){
				p = new Plate(x,y,false, true, b);
			}
			else if(m % 5 == 0){
				p = new Plate(x,y, true, false, 0);
			}
			else
				p = new Plate(x,y, false, false, 0);
			addPlate(p);
		}
		
		
		
	}
	public void checkAndRemove(){
		Enumeration<Plate> venum = plates.elements();
		Enumeration<Enemy> venum2 = enemies.elements();
		while(venum.hasMoreElements()){
			Plate p = (Plate)venum.nextElement();
			if(p.getY() > 600){
				mm.getGC().incrementScore(5);
				plates.removeElement(p);
				mm.deleteFromUI(p);
			}
		}
		while(venum2.hasMoreElements()){
			Enemy p = (Enemy)venum2.nextElement();
			if(p.getY() > 600){
				mm.getGC().incrementScore(50);
				enemies.removeElement(p);
				mm.deleteFromUI(p);
			}
		}
	}
	
	public void removeFromCanvas(Bonus b){
		mm.deleteFromUI(b);
	}
	
	public void removePlate(Plate p){
		plates.removeElement(p);
	}
	public void generateEnemy() {
		Random generator = new Random();
		int direction = generator.nextInt(2);
		Enemy e = new Enemy(0,0,direction);
		enemies.addElement(e);
	}
	
	
	public void removeEnemy(){
		
	}
	public void removeBonus(){
		
	}
	public Vector<Plate> getPlates(){
		return plates;
	}
	public Vector<Enemy> getEnemies(){
		return enemies;
	}
	public Vector<Bonus> getBonuses(){
		return bonuses;
	}
	public Vector<GameObject> getEnemiesAsO(){
		Vector<GameObject> en = new Vector<GameObject>();
		Enumeration<Enemy> venum = enemies.elements();
		while(venum.hasMoreElements()){
			Enemy p = (Enemy)venum.nextElement();
				en.addElement(p);
				//System.out.println("downplate eklendi");
			
		}
		return en;
	}
	
	public Vector<GameObject> getBonusesAsO(){
		Vector<GameObject> en = new Vector<GameObject>();
		Enumeration<Bonus> venum = bonuses.elements();
		while(venum.hasMoreElements()){
			Bonus p = (Bonus)venum.nextElement();
				en.addElement(p);
				//System.out.println("downplate eklendi");
			
		}
		return en;
	}
	
	public Vector<GameObject> getDownNoodle(double y){
		Vector<GameObject> downPlates = new Vector<GameObject>();
		Enumeration<Plate> venum = plates.elements();
		while(venum.hasMoreElements()){
			Plate p = (Plate)venum.nextElement();
			if(p.getY() > y){
				downPlates.addElement(p);
				//System.out.println("downplate eklendi");
			}
		}
		
		return downPlates;
	}

}
